package com.jqkb.pages;

import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.jqkb.R;
import com.jqkb.adapters.ForwardPagerAdapter;

public class ForwardListActivity extends AppCompatActivity implements View.OnClickListener, ViewPager.OnPageChangeListener {

    private ViewPager pager;
    private TextView sendListTv;
    private TextView targetListTv;
    private TextView allListTv;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_forward_list);
        pager = (ViewPager) findViewById(R.id.viewpager);
        sendListTv = (TextView) findViewById(R.id.sendListTv);
        targetListTv = (TextView) findViewById(R.id.targetListTv);
        allListTv = (TextView) findViewById(R.id.allListTv);
        allListTv.setSelected(true);
        sendListTv.setOnClickListener(this);
        targetListTv.setOnClickListener(this);
        allListTv.setOnClickListener(this);
        pager.setAdapter(new ForwardPagerAdapter(getSupportFragmentManager(),this));
        pager.addOnPageChangeListener(this);
        pager.setOffscreenPageLimit(3);
    }


    @Override
    public void onClick(View v) {
        setEnable();
        switch (v.getId()) {
            case R.id.allListTv:
                sendListTv.setSelected(true);
                pager.setCurrentItem(0);
                break;
            case R.id.sendListTv:
                targetListTv.setSelected(true);
                pager.setCurrentItem(1);
                break;
            case R.id.targetListTv:
                targetListTv.setSelected(true);
                pager.setCurrentItem(2);
                break;

        }

    }


    public void setEnable() {
        sendListTv.setSelected(false);
        targetListTv.setSelected(false);
        allListTv.setSelected(false);
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        setEnable();
        if (position == 0) {
            allListTv.setSelected(true);

        } else if (position==1){
            sendListTv.setSelected(true);
        }
        else if (position==2){
            targetListTv.setSelected(true);
        }

    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}
